
/**
 * @description 表格上方的的面板 控制 导出 新建 配置等功能
 * @desc 
 * @author 韩
 */
import React, { useEffect, useState } from "react";
import { SettingOutlined, FormOutlined } from '@ant-design/icons';
import { Button, Space } from "antd";
import TableColumnsSetModal from "./setColumns";
import { authButton } from "@/common";

const TableActionPanel = ({ columns = Array, useColumns = Array, setUseColumns = Function, selectRecords = Array, tablePanelConfig = Array }) => {
    const [show, setShow] = useState(false);
    const [newSelectRows, setNewSelectRows] = useState(selectRecords);
    useEffect(() => {
        setNewSelectRows(selectRecords);
        return () => {
            setNewSelectRows([]);
        }
    }, [selectRecords]);



    return (
        <>
            <TableColumnsSetModal
                show={show}
                setShow={setShow}
                title="表格列配置"
                columns={columns}
                useColumns={useColumns}
                setUseColumns={setUseColumns}
            />
            <div
                style={{
                    width: "100%",
                    marginTop: "10px",
                    marginBottom: "10px",
                    display: "flex",
                    justifyContent: "flex-end"
                }}
            >
                <Space wrap>
                    {
                        tablePanelConfig.map((item, index) => {
                            if (item.show) {
                                return (item.render && item.render(newSelectRows, index)) || <Button
                                    key={index}
                                    type={item.type || "primary"}
                                    icon={item.icon || <FormOutlined />}
                                    onClick={() => { item.onClick(newSelectRows) }}
                                >{item.text || "按钮"}</Button>
                            }

                        })
                    }

                    <Button onClick={() => setShow(true)} icon={<SettingOutlined />}></Button>
                </Space >

            </div>


        </>
    )
}
export default TableActionPanel